package com.aldobucchi.utils
{
	
	import flash.events.Event;
	import flash.events.EventDispatcher;



/**
 *  
 * 
 *  @eventType flash.events.Event.CHANGE
 */
[Event(name="change", type="flash.events.Event")]		
	


	/**
	 * 
	 * This is a generic utility class that serves a very simple purpose:
	 * <p>
	 * It exposes one public readwrite bindable property that dispatches a change event
	 * upon every modification.
	 * </p>
	 * 
	 * A common usage pattern:
	 * 	<ol>
	 * 		<li>Create a ValueHolder instance and set a value</li>
	 * 		<li>Pass the instance to some other part of the program while keeping a local reference to it</li>
	 * 		<li>Modify the value later. Any part of the program that is listening to the event will be notified of the change</li>
	 * 	</ol>
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */
	public class ValueHolder extends EventDispatcher
	{
		
		private var _value:*;
		
		[Bindable("change")]
		public function get value( ):*
		{
			return _value;
		}
		
		public function set value( v:* ):void
		{
			
			if ( v === _value ) // dismiss
				return;
		
			_value = v;
			
			dispatchEvent( new Event( Event.CHANGE ) );
		
		}
		
		
	}

}